/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package stuff.util;

import org.slf4j.LoggerFactory;
import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mail.MailException;
import org.springframework.mail.MailSender;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.stereotype.Service;
import stuff.Account;


/**
 *
 * @author Николай
 */
@Service
public class MailManager {

    final private Logger log = LoggerFactory.getLogger(MailManager.class);

    @Autowired
    private MailSender mailSender;

    @Autowired
    private SimpleMailMessage templateMessage;

    public MailManager() {
    }

    public void sendPassword(Account acc) throws MailException {
        log.info("call send password");
        String text = String.format(
                "Dear %s, thank you for registration. "
                + "Your login is %s. Password: %s",
                acc.getFullName(),
                acc.getUserName(),
                acc.getPassword());
        SimpleMailMessage msg = new SimpleMailMessage(this.templateMessage);
        msg.setTo(acc.getEmail());
        msg.setText(text);
        log.info("send mail msg {}", msg);
        this.mailSender.send(msg);
    }
}
